<extend name="Layout/ins_page" />
<block name="content">
	<div class="page-header clearfix">
		<div class="dropdown col-sm-8">			
			<b class="dropdown-toggle" data-toggle="dropdown"><span class="title">全部</span><span class="fa fa-caret-down"></span></b>
			<ul class="dropdown-menu">
				<li gid="">
					<a>全部</a>
				</li>
				
			</ul>
		</div>
		<div class="col-sm-4 pull-right">
			<div class="search_box">
				<div class="input-group ">
					<input type="hidden" value="abc" >
					<input  class="form-control" type="text"  name="keyword" id="keyword" onkeydown="key_local_search();"/>
					<div class="input-group-btn">
						<a class="btn btn-sm btn-info" onclick="btn_local_search();"><i class="fa fa-search" ></i> </a>
					</div>
				</div>
			</div>
		</div>
	</div>
	<form id="form_data" name="form_data" method='post'>
		<div class="operate panel panel-default">
			<div class="panel-body">
				<div class="pull-left">
					
					<a class="btn btn-sm btn-danger" onclick="del();" >删除</a>
					
				</div>
				<div class="pull-right">
					<a class="btn btn-sm btn-primary" onclick="add();">新建</a>
				</div>
			</div>
		</div>
		<div class="ul_table border-top border-bottom">
			<empty name="list">
				<ul>
					<li class="no-data">
						没找到数据
					</li>
				</ul>
				<else/>
				<ul>
                                    <li class="thead">
                                        <div class="pull-left">
                                                <span class="col-6 text-center">选择</span>
                                                <span class="col-10 text-center">APP名称</span>
                                                <span class="col-10 text-center">广告类型</span>
                                                <span class="col-10 text-center">包名</span>

                                        </div>
                                        <div class="pull-right">
                                                <span class="col-6 text-center">是否开启</span>
                                                <span class="col-9 text-center">添加日期</span>
                                                <span class="col-9 text-center">操作</span>
                                        </div>
			
                                    </li>
					<foreach name="list" item="vo">
						<li class="tbody">
							<div class="pull-left">
                                                            <span class="col-6 text-center">
                                                                <input class="ace" type="checkbox" name="id[]" value="{$vo.id}"/>
                                                            </span>
                                                            <span class="col-10 text-center data">{$vo.name}</span>
                                                            <span class="col-10 text-center"><if condition="$vo['type'] eq 1">360广告<else/>百度广告</if></span>
                                                            <span class="col-10 text-center data">{$vo.package}</span>
                                                        </div>
                                                    <div class="pull-right">
                                                        <span class="col-6 text-center"><if condition="$vo['is_lock'] eq 1"><font color="red">否</font><else/>是</if></span>
                                                        <span class="col-9 text-center">{$vo.create_time|to_date='Y-m-d'}</span>
                                                        <span class="col-9 text-center"><a  onclick="edit({$vo.id});">编辑</a>&nbsp;</span>
                                                   </div>
						</li>
					</foreach>
				</ul>
			</empty>
		</div>
	</form>
</block>
<block name="js">
	<script type="text/javascript">
		function add() {
			window.open("{:U('add')}", "_self");
			return false;
		}

		function edit(val) {
			
			if (val == undefined) {
				ui_error("请选择要编辑的APP");
				return false;
			} else {
				window.open(fix_url("{:U('edit')}?id=" + val), "_self");
			}
		}

		function del() {
			count = $("li.tbody :checked").length;
			if (count == 0) {
				ui_error("请选择要删除的数据");
				return false;
			}
			ui_confirm('确定要删除吗?', function() {
				if ($("#form_data .ul_table input:checked").length == 0) {
					$("li.tbody.active :checkbox").attr("checked", true);
				}
				sendForm("form_data", "{:U('del')}");
				$("#form_data input:checked").each(function() {
					$(this).parents("li").remove();
				});
			});
		}
                
               

		function apply() {
			if ($("#form_data .ul_table input:checked").length == 0) {
				ui_error("请选择数据");
				return false;
			}
			sendForm("form_data", "{:U('set_tag')}", "{:U('index')}");
		}

		function create_new_tag() {
			$(".cmd").hide();
			$(".new_tag").css("display", "block");
			$(".apply").show();
		}

		function key_local_search() {
			if (event.keyCode == 13) {
				$(".ul_table li").hide();
				val = $("#keyword").val().toUpperCase();
				if (val.length == 0) {
					$(".page-header .title").html("全部");
				} else {
					$(".page-header .title").html("搜索结果");
				}
				$(".ul_table li .data").each(function() {
					if ($(this).text().indexOf(val) >= 0) {
						$(this).parents("li").show();
					};
				});
			}
		}

		function btn_local_search() {
			$(".ul_table li").hide();
			val = $("#keyword").val().toUpperCase();
			if (val.length == 0) {
				$(".title nobr").html("全部");
			} else {
				$(".title nobr").html("搜索结果");
			}
			$(".ul_table li .data").each(function() {
				if ($(this).text().indexOf(val) >= 0) {
					$(this).parents("li").show();
				};
			});
			return false;
		}

		$(document).ready(function() {
			set_return_url();
			$(".page-header .dropdown-menu li").click(function() {
				$("#keyword").val("");
				$(".ul_table li").hide();
				gid = $(this).attr("gid");
				$(".page-header .title").html($(this).text());
				
			});

			
			$("li.tbody").click(function() {
				$(".table input:checkbox").attr("checked", false);
				$(".tag_list input[name='tag[]']").attr("checked", false);
			});
		});
	</script>
</block>